<template>
    <div class="container">
        <addThresholdView ref="addThresholdView" />
        <div class="main">
            <div class="header felx">
                <div class="header_l flex">
                    <!-- <div class="header_btn flex">
                        <img src="../../assets/fileFlow_add.png">
                        <p>新建盘点</p>
                    </div> -->
                </div>
                <div class="header_r flex">
                    <div class="serachBox flex">
                        <div class="flex">
                            <p>物资名称</p>
                            <!-- <el-icon>
                                <ArrowDown />
                            </el-icon> -->
                        </div>
                        <input type="text" v-model="inputValue">
                        <button @click="getList">搜索</button>
                    </div>
                </div>
            </div>
            <div class="borderBox">

                <div class="table_box">
                    <!-- <p class="title">库存列表</p>
                    <div class="cardBox">
                        <div class="card_header flex">
                            <p style="width: 60px;margin-left: 10px;">序号</p>
                            <p style="width: 100px;margin-left: 10px;">物资名称</p>
                            <p style="width: 150px;">预警阈值</p>
                            <p style="width: 200px;">物资编码</p>
                            <p style="width: 150px;">可用数量</p>
                            <p style="width: 150px;">入库数量</p>
                        </div>
                        <div class="card_li flex" :class="{ 'card_li_active': active === index }"
                            v-for="(item, index) in list">
                            <div style="width: 100%; height: 50px;" class="flex">
                                <div style="width: 60px;margin-left: 10px;">{{ item.id }}</div>
                                <div style="width: 100px;margin-left: 10px;">{{ item.name }}</div>
                                <div style="width: 150px; ">{{ item.warningThreshold }}</div>
                                <div style="width: 200px;">{{ item.code }}</div>
                                <div style="width: 150px;">{{ item.availableQuantity }}</div>
                                <div style="width: 150px;">{{ item.stockQuantity }}</div>
                            </div>

                        </div>
                    </div> -->



                    <el-table :data="list" border style="width: 100%;" scrollTo :row-class-name="tableRowClassName"
                        :header-cell-style="headerCellStyle" :row-style="tableRowStyle">
                        <el-table-column prop="id" label="序号" width="150">
                            <template #header>
                                <div class="header_icon">
                                    <span>序号</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="物资名称">
                            <template #header>
                                <div class="header_icon">
                                    <span>物资名称</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="stockQuantity" label="入库数量">
                            <template #header>
                                <div class="header_icon">
                                    <span>入库数量</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="availableQuantity" label="可用数量">
                            <template #header>
                                <div class="header_icon">
                                    <span>可用数量</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="warningThreshold" label="预警阈值">
                            <template #header>
                                <div class="header_icon">
                                    <span>预警阈值</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="code" label="流水号">
                            <template #header>
                                <div class="header_icon">
                                    <span>流水号</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="availableQuantity" label="可用数量">
                            <template #header>
                                <div class="header_icon">
                                    <span>可用数量</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                        </el-table-column> -->

                        <el-table-column prop="stockQuantity" label="预警等级" width="200">
                            <template #header>
                                <div class="header_icon">
                                    <span>预警等级</span>
                                    <el-icon class="rotate">
                                        <MoreFilled />
                                    </el-icon>
                                </div>
                            </template>
                            <template style="display: block" #default="scope">
                                <div class="warning" style="color: #FF4C43;font-size: 13px;"
                                    :class="{ 'run': scope.row.warningThreshold > scope.row.stockQuantity }"
                                    v-if="scope.row.warningThreshold > scope.row.stockQuantity"><img
                                        src="../../assets/inventoryWarning_icon1.png">
                                    <p>（需要立即添加库存）</p>
                                </div>
                                <div class="warning" style="color: #09B631;font-size: 13px;" v-else><img
                                        src="../../assets/inventoryWarning_icon2.png">
                                    <p>安全库存</p>
                                </div>
                            </template>
                        </el-table-column>

                        <el-table-column label="操作" width="150px" fixed="right">
                            <template style="display: block" #default="scope">
                                <el-button class="edit_btn" size="small" type="success" style="margin-right: 10px;"
                                    @click="editHandle(scope.row.id)">重设阈值
                                </el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>

                <div style="margin-top: 10px" class="pageBox flex">
                    <el-config-provider :locale="locale">
                        <el-pagination :total="total" :current-page="page" :page-size="pageSize" background
                            layout="prev, pager, next, sizes" :page-sizes="[5, 10, 15, 20, 30, 40, 50, 100]"
                            @size-change="changePageSize" @current-change="changeCurrentPage" />
                        <div class="flex">
                            <p>第 {{ page }} 条</p>
                            <p>共 {{ total }} 条数据</p>
                        </div>
                    </el-config-provider>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { httpService } from "@/utils/httpService";
import { ElConfigProvider, ElMessage } from "element-plus";
import { MoreFilled, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, } from "@element-plus/icons-vue";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import addThresholdView from "../../components/medicalProduct/addThresholdView.vue";

export default {
    name: "MedicalProductLogin",
    components: { ElMessage, MoreFilled, addThresholdView, CaretLeft, CaretRight, ArrowLeftBold, ArrowRightBold, ArrowDown, ElConfigProvider },
    data() {
        return {
            page: 1,
            pageSize: 10,
            total: 0,
            expandedRow: null,
            active: '',
            list: [],
            inputValue: "",

        };
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    computed: {},
    mounted() {
        this.getList()
    },
    methods: {
        // clickHandle(index) {
        //     if (this.active === index) {
        //         this.active = ""
        //     } else {
        //         this.active = index
        //     }
        // },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return 'warning-row'
            } else if (rowIndex % 2 == 1 && this.expandedRow == row) {
                return 'warning-row expanded-row'
            } else if (this.expandedRow == row) {
                return 'expanded-row'
            } else {
                return ""
            }
        },
        headerCellStyle() {
            return {
                background: '#f2f2f2',
            };
        },
        tableRowStyle({ row, rowIndex }) {
            if (rowIndex % 2 === 1) {
                return {
                    background: '#F5F5F5',
                };
            }
        },
        editHandle(id) {
            this.$refs.addThresholdView.form.id = id
            this.$refs.addThresholdView.flag = true
        },


        changePageSize(size) {
            this.pageSize = size;
            this.getList()
        },
        changeCurrentPage(page) {
            this.page = page;
            this.getList()
        },


        getList() {
            httpService(`/javaApi/materials/list/${this.page}/${this.pageSize}`, { name: this.inputValue, orderBy: 'warningThreshold' }, "get").then((data) => {
                console.log(data);
                if (data) {
                    this.total = data.total
                    this.list = data.list
                }
            });
        },
    },
};
</script>
<style scoped>
* {
    padding: 0;
    margin: 0;
}

.flex {
    display: flex;
    align-items: center;
}

.container {
    width: calc(100vw - 30px);
    height: calc(100vh - 30px);
    padding: 15px 15px;
    background-color: #EEF7FB;
}

.main {
    width: calc(100% - 30px);
    height: calc(100% - 30px);
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
}

.header {
    height: 35px;
    /* background-color: chocolate; */
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header_btn {
    width: 99px;
    height: 32px;
    background-color: #6F72FF;
    border-radius: 5px;
    justify-content: center;
    font-size: 14px;
    color: #fff;
    margin-right: 15px;
    cursor: pointer;
}

.header_btn img {
    width: 17px;
    height: 18px;
    margin-right: 5px;
}

.serachBox {
    color: #666666;
    font-size: 14px;
    width: 333px;
    height: 36px;
    border: 1px solid #D0D0D0;
    box-sizing: border-box;
    border-radius: 20px;
}

.serachBox .flex {
    justify-content: center;
    border-right: 1px solid #D0D0D0;
    margin-right: 10px;
    padding: 0 5px 0 15px;
    color: #666666;
    cursor: pointer;
}

.serachBox input {
    height: calc(100% - 4px);
    border: none;
    outline: none;
    flex: 1;
}

.serachBox button {
    width: 59px;
    height: 30px;
    border-radius: 15px;
    border: none;
    background-color: #6F72FF;
    color: #fff;
    font-size: 14px;
    margin-right: 2px;
}


.borderBox {
    height: calc(100% - 50px);
    border: 1px solid #DFDFDF;
    border-radius: 5px;
    box-sizing: border-box;
    margin-top: 15px;
}

.borderTop {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.workList {
    display: flex;
}

.workList p {
    color: #666;
    font-size: 14px;
    margin-left: 20px;
}

.workList p span {
    color: #6F72FF;
}

.borderTop .flex {
    margin-right: 20px;
}

.borderTop_btn {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #666666;
    margin-left: 40px;
    cursor: pointer;
}

.header_icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.table_box {
    width: calc(100vw - 283px);
    height: calc(100% - 53px);
    /* width: calc(100vw - 342px);
    height: calc(100% - 83px); */
    display: flex;
    align-content: flex-start;
    flex-wrap: wrap;
    /* padding: 15px; */
    overflow-y: auto;
}

::v-deep .expanded-row {
    background-color: #668655 !important;
}

.rotate {
    transform: rotate(90deg);
}


.el-scrollbar__bar {
    z-index: 11;
    overflow-x: hidden;
    position: sticky;
}

.el-table.el-table--border {
    overflow: unset;
}


.pageBox {
    background-color: #f6f6f6;
    padding: 5px 0;
    border-top: 1px solid #e7e7e7;
    border-radius: 0 0 5px 5px;
}

.el-pagination {
    margin-left: 10px;
}

.pageBox {
    justify-content: space-between;
}

.pageBox .flex {
    color: #666;
    font-size: 14px;
    margin-right: 10px;
}

.pageBox .flex p {
    color: #666;
    font-size: 14px;
    margin-right: 20px;
}

.rowBox {
    padding-left: 100px;
}

.rowBox_l {
    margin-right: 100px;
}

.rowName {
    color: #BFBFBF;
    font-size: 13px;
    margin-right: 25px;
    width: 60px;
    text-align: right;
}

.rowContent {
    color: #666666;
    font-size: 13px;
}


.title {
    color: #333;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
}

.cardBox {
    width: 100%;
    height: 100%;
    /* background-color: #a5a5a5; */
}

.card_header {
    color: #333;
    font-size: 13px;
    font-weight: bold;
}

.card_li {
    flex-direction: column;
    border: 1px solid #DFDFDF;
    min-height: 50px;
    border-radius: 5px;
    margin-top: 10px;
    font-size: 13px;
    color: #666;
}

.card_li_active {
    background-color: #6F72FF !important;
    color: #fff !important;
    transition: all 0.3s ease-in;
    box-shadow:
        0 5px 10px rgba(26, 27, 63, 0.1),
        /* 下边阴影大一点 */
        0 3px 5px rgba(26, 27, 63, 0.1);
    /* 左右阴影 */
}

.card_li img {
    width: 57px;
    height: 38px;
    object-fit: cover;
}

.cardExpend {
    width: 100%;
    height: 150px;
    background-color: #fff;
    border-radius: 0 0 4px 4px;
}

.color {
    color: #292CC1;
}

.color1 {
    color: #FF4C43;
}

.color2 {
    color: #09B631;
}


.edit_btn {
    width: 60px;
    background-color: transparent;
    color: #007EFF;
    border: none;
}

.del_btn {
    width: 60px;
    background-color: transparent;
    color: #FF0000;
    border: none;
}

.warning {
    display: flex;
    align-items: center;
}

.warning img {
    margin-right: 5px;
}


.run {
    animation: blink 1s infinite;
}

@keyframes blink {
    0% {
        opacity: 1;
        /* 开始时完全可见 */
    }

    50% {
        opacity: 0;
        /* 中间时完全透明 */
    }

    100% {
        opacity: 1;
        /* 结束时重新可见 */
    }
}
</style>